<template>
  <div class="app-container">
    <!-- <el-drawer title :visible.sync="showFlag" size="95%"> -->
    <!-- <div style="padding:0 20px;"> -->
    <!-- <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          v-show="showSearch"
          label-width="100px"
        >
          <el-form-item label="检测开始日期" prop="checkStartDate">
            <el-date-picker
              clearable
              v-model="queryParams.checkStartDate"
              type="date"
              value-format="yyyy-MM-dd 00:00:00"
              placeholder="请选择开始日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="检测结束日期" prop="checkEndDate">
            <el-date-picker
              clearable
              v-model="queryParams.checkEndDate"
              type="date"
              value-format="yyyy-MM-dd 23:59:59"
              placeholder="请选择结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="物料名称" prop="snCode">
            <el-input
              v-model="queryParams.snCode"
              placeholder="请输入物料名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
    </el-form>-->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="检验单编号" prop="oqcCode">
        <el-input v-model="queryParams.oqcCode" placeholder="请输入检验单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="发货单据编号" prop="fbillno">
        <el-input v-model="queryParams.fbillno" placeholder="请输入发货单据编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="客户名称" prop="clientName">
        <el-input v-model="queryParams.clientName" placeholder="请输入客户名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="出货日期" prop="outDate">
        <el-date-picker clearable v-model="queryParams.outDate" type="date" value-format="yyyy-MM-dd 00:00:00"
          placeholder="请选择出货日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="质检状态" prop="qualityStatus">
        <el-select v-model="queryParams.qualityStatus" placeholder="请选择质检状态" clearable>
          <el-option label="未质检" :value="0" />
          <el-option label="质检中" :value="1" />
          <el-option label="已质检" :value="2" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="qcindexList">
      <el-table-column label="序号" align="center" width="50px" prop="issueCode">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检验单编号" align="center" width="160" prop="oqcCode">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleView(scope.row)">{{ scope.row.oqcCode }}</el-button>
        </template>
      </el-table-column>
      <!-- <el-table-column label="检验单名称" align="center" prop="oqcName"></el-table-column> -->
      <el-table-column label="发货单据编号" align="center" prop="fbillno"></el-table-column>
      <!-- <el-table-column label="送检单号" align="center" width="120" prop="inspectionCode"></el-table-column> -->
      <el-table-column label="订单号" align="center" prop="workorderCode"></el-table-column>
      <el-table-column label="客户名称" align="center" prop="customerName"></el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">{{ scope.row.status == '0' ? "未检验" : scope.row.status == '1' ? "已检验" : "未检验" }}</template>
      </el-table-column>
      <el-table-column label="产品编码" align="center" prop="productCode"></el-table-column>
      <el-table-column label="产品名称" align="center" prop="productName"></el-table-column>
      <el-table-column label="规格型号" align="center" prop="productSpec"></el-table-column>
      <el-table-column label="报检数量" align="center" prop="quinspection"></el-table-column>
      <el-table-column label="报检时间" align="center" prop="submissionDate"></el-table-column>
      <el-table-column label="检验员" align="center" prop="inspector"></el-table-column>
      <el-table-column label="检验时间" align="center" prop="inspectionDate"></el-table-column>
      <!-- <el-table-column label="审核员" align="center" prop="auditor"></el-table-column>
      <el-table-column label="审核时间" align="center" prop="auditDate"></el-table-column>-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleAdd(scope.row)"
            v-hasPermi="['mes:qc:oqc:check']" v-if="scope.row.status == '0'">检验</el-button>
          <el-button size="mini" type="text" icon="el-icon-view" v-if="scope.row.status == '1'"
            @click="viewReport(true, scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改检测项对话框 -->
    <el-drawer :title="title" :visible.sync="open" size="80%" :before-close="cancel" custom-class="demo-drawer"
      :append-to-body="true">
      <div class="demo-drawer__content dialogContent">
        <el-form ref="form" :model="form" :rules="rules" label-width="auto">
          <el-row>
            <el-col :span="6">
              <el-form-item label="产品编码" prop="productCode">
                <el-input v-model="form.productCode" placeholder :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="产品名称：" prop="productName">
                <el-input v-model="form.productName" placeholder :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="规格型号：" prop="productSpec">
                <el-input v-model="form.productSpec" placeholder :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="检验日期:" prop="inspectionDate">
                <el-date-picker clearable v-model="form.inspectionDate" type="date" value-format="yyyy-MM-dd"
                  placeholder="请选择开始日期"></el-date-picker>
                <!-- :picker-options="pickerOptions" -->
                <!-- <el-input
                      v-model="form.inspectionDate"
                      placeholder
                      :disabled="optType=='add'? false:true"
                />-->
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="合同号:" prop="ftext4">
                <el-input v-model="form.ftext4" placeholder disabled />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="客户:" prop="number">
                <el-input v-model="form.number" placeholder disabled />
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="技术分解单号：" prop="ftext1">
                <el-input v-model="form.ftext1" placeholder :disabled="optType == 'add' ? false : true" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="报检数量：" prop="quinspection">
                <el-input-number :controls="false" :disabled="true" v-model="form.quinspection" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="抽样数量：" prop="samplingQuantity">
                <el-input-number :controls="false" v-model="form.samplingQuantity" :max="form.quinspection" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="合格数量：" prop="qualifiedQuantity">
                <el-input v-model="form.qualifiedQuantity" placeholder :disabled="optType == 'add' ? false : true"
                  @change="(value) => autoInput(value, 'qualifiedQuantity', 'unqualifiedQuantity')" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="不合格数量：" prop="unqualifiedQuantity">
                <el-input v-model="form.unqualifiedQuantity" placeholder :disabled="optType == 'add' ? false : true"
                  @change="(value) => autoInput(value, 'unqualifiedQuantity', 'qualifiedQuantity')" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-table v-loading="loading1" :data="templateList" :span-method="objectSpanMethod">
              <el-table-column type="index" label="序号" width="50" :index="indexMethod"></el-table-column>
              <el-table-column label="检查项目" align="center" prop="indexType" width="160px">
                <template slot-scope="scope">
                  <dict-tag :options="dict.type.mes_index_type" :value="scope.row.indexType" />
                </template>
              </el-table-column>

              <el-table-column label="检查内容" align="center" prop="indexName" width="260px" />

              <el-table-column v-for="(item, i) in form.samplingQuantity" :key="i" align="center" prop="checkResult"
                width="240px">
                <template slot="header" slot-scope="scope">
                  <div class="headerDiv">
                    <el-input v-model="snObj[`snCode${i}`]" size="mini" placeholder="输入sn码" @input="snbutton"
                      id="sncode-input" />
                    <!-- <el-radio-group
                      v-model="radioObj[`check${i}`]"
                      @input="(value)=>checkAllChange(value,i)"
                    >
                      <el-radio :label="1" value="1">√</el-radio>
                    </el-radio-group>-->
                  </div>
                </template>
                <template slot-scope="scope">
                  <!-- <el-form-item label="" prop="checkResult" class="tableItem"> -->
                  <div v-if="optType == 'add' || optType == 'edit'">
                    <el-radio-group v-model="scope.row[`checkResult${i}`]" @input="checkChange">
                      <el-radio :label="1" value="1">√</el-radio>
                      <el-radio :label="0" value="0">×</el-radio>
                    </el-radio-group>

                    <!-- {{ scope.row.attr1 && JSON.parse(scope.row.attr1) }} -->
                    <!-- judegShowInput(scope.row.attr1,scope.$index) -->

                    <ul v-if="scope.row.attrObj.type == '2'">
                      <li class="mInput">
                        <span>标准值</span>
                        <el-input v-model="scope.row.attrObj.standard" style="width: 70px;"
                          @input="(e) => inputStandard(e, scope.row, scope.$index, i)" />
                        <el-input v-model="scope.row.attrObj[`num${i}`]" style="width: 70px;"
                          @input="(e) => inputStandard(e, scope.row, scope.$index, i)" />
                      </li>
                    </ul>
                    <ul v-if="scope.row.attrObj.type == '4'">
                      <li class="mInput">
                        <span>长</span>
                        <el-input v-model="scope.row.attrObj.lStandard" style="width: 70px;"
                          @input="(e) => inputCheckout(e, scope.row, scope.$index, i)" />
                        <el-input v-model="scope.row.attrObj[`lNum${i}`]" style="width: 70px;"
                          @input="(e) => inputCheckout(e, scope.row, scope.$index, i)" />
                      </li>
                      <li class="mInput">
                        <span>宽</span>
                        <el-input v-model="scope.row.attrObj.wStandard" style="width: 70px;"
                          @input="(e) => inputCheckout(e, scope.row, scope.$index, i)" />
                        <el-input v-model="scope.row.attrObj[`wNum${i}`]" style="width: 70px;"
                          @input="(e) => inputCheckout(e, scope.row, scope.$index, i)" />
                      </li>
                      <li class="mInput">
                        <span>高</span>
                        <el-input v-model="scope.row.attrObj.hStandard" style="width: 70px;"
                          @input="(e) => inputCheckout(e, scope.row, scope.$index, i)" />
                        <el-input v-model="scope.row.attrObj[`hNum${i}`]" style="width: 70px;"
                          @input="(e) => inputCheckout(e, scope.row, scope.$index, i)" />
                      </li>
                    </ul>
                  </div>
                  <!-- </el-form-item> -->
                </template>
              </el-table-column>
            </el-table>
          </el-row>

          <el-row>
            <el-col :span="24" class="imgDiv">
              <el-form-item label="检验结果" prop="checkResult">
                <el-radio-group v-model="form.checkResult" :disabled="QcFqcAcInspectionHead.status == '0' ? false : true">
                  <el-radio :label="1">√</el-radio>
                  <el-radio :label="0">×</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="备注:" prop="remark">
                <el-input v-model="form.remark" placeholder="输入备注"
                  :disabled="QcFqcAcInspectionHead.status == '0' ? false : true" :autosize="{ minRows: 2, maxRows: 5 }"
                  style="width: 450px; height: 100px" type="textarea"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <div v-if="form.checkResult == 0">
            <el-row v-for="(item, i) in failedSncode" :key="item.snCode"
              style="box-shadow: 0 0 7px rgb(186, 186, 186);padding:0 20px;margin-bottom:15px">
              <p>
                <span>SN码：</span>
                <span>{{ item.snCode }}</span>
              </p>
              <el-col :span="24">
                <el-form-item label="不合格品处理方式" prop="repairState">
                  <el-radio-group v-model="item.repairState">
                    <el-radio :label="1">返工</el-radio>
                    <el-radio :label="2">返修</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="检验记录">
                  <el-table :data="item.errorList">
                    <el-table-column label="类型选择" align="center" prop="indexType">
                      <template slot-scope="scope">
                        <el-select v-model="scope.row.indexType" placeholder="请选择检测项类型" clearable>
                          <el-option v-for="(dict, index) in abnormalList" :key="index" :label="dict.indexTypeName"
                            :value="dict.indexType" />
                        </el-select>
                      </template>
                    </el-table-column>

                    <el-table-column label="异常描述" align="center" prop="describeData">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.describeData" placeholder type="textarea" />
                      </template>
                    </el-table-column>
                    <el-table-column label="文件上传" align="center" prop="checkResult">
                      <template slot-scope="scope">
                        <ImageUpload :limit="1" :value="scope.row.sopUrl" :fileSize="15"
                          @input="(url) => handleImgUplaoded(url, i, scope.$index)" @onRemoved="handleImgRemoved">
                        </ImageUpload>
                      </template>
                    </el-table-column>
                    <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                      <template slot-scope="scope">
                        <el-button size="medium" type="text" icon="el-icon-circle-plus-outline"
                          @click="errorAdd(item, i)"></el-button>
                        <el-button v-if="scope.$index != 0" size="medium" type="text" icon="el-icon-remove-outline"
                          @click="errorDel(scope.$index, i)"></el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-form>
      </div>
      <div class="demo-drawer__footer" style="text-align: right;">
        <el-button type="primary" @click="cancel" v-if="optType == 'view'">返回</el-button>
        <el-button type="primary" @click="submitForm" v-else>确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-drawer>

    <oqc-detail v-if="detailVisible" ref="detailOrUpdate"></oqc-detail>
    <!-- </div> -->
    <!-- </el-drawer> -->
  </div>
</template>

<script>
import oqcDetail from "./oqc_detail.vue";

import {
  listInspection,
  getInspection,
  delInspection,
  addInspection,
  updateInspection,
  templateindexList,
  getabnormalList,
  OqccheckSncode
} from "@/api/mes/qc/qcOqcInspection";
import { genCode } from "@/api/mes/md/rule";
export default {
  name: "ooqc1",
  dicts: ["mes_index_type"],
  components: { oqcDetail },
  data() {
    return {
      //自动生成编码
      autoGenFlag: false,
      optType: undefined,
      showFlag: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 检测项表格数据
      qcindexList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        snCode: null,
        indexName: null,
        indexType: null,
        qcTool: null
        // headId: null
      },
      // 表单参数
      form: {},
      // sncode集合
      snObj: {},
      radioObj: {},
      // 表单校验
      rules: {
        snCode: [{ required: true, message: "SN码不能为空", trigger: "blur" }],
        checkResult: [
          { required: true, message: "检验结果不能为空", trigger: "change" }
        ],
        headEndCheckType: [
          { required: true, message: "类型不能为空", trigger: "change" }
        ]
      },
      indexCodeDisabled: false,
      // 模板列表
      templateList: [],
      loading1: false,
      spanArr: [],
      // 异常记录列表
      errorList: [],
      // 不合格数
      failedSncode: [],
      // 首页列表信息
      QcFqcAcInspectionHead: {},
      //模块id
      templateId: "",
      //异常列表
      abnormalList: [],
      //详情页面
      detailVisible: false
      // pickerOptions: {
      //   disabledDate(time) {
      //     return time.getTime() > Date.now();
      //   }
      // }
    };
  },
  created() {
    this.getList();
  },

  methods: {
    init(row) {
      console.log(row, "子组件的row");
      //调接口需要的id
      this.showFlag = true;
      this.queryParams.headId = row.id;
      this.getList();
    },
    //自定义模板序号
    indexMethod(index) {
      if (this.spanArr[index]) {
        if (index == 0) {
          return 1;
        } else {
          let count = 0;
          for (let i = 0; i <= index; i++) {
            if (this.spanArr[i] > 0) {
              count++;
            }
          }
          console.log("count", count);
          return count;
        }
      }
    },
    /** 查询检测项列表 */
    getList() {
      this.loading = true;
      listInspection(this.queryParams).then(response => {
        console.log(response, "tableres");
        this.qcindexList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        checkResult: null,
        snCode: null,
        indexName: null,
        indexType: null,
        headEndCheckType: null,
        remark: null,
        inspectionDate: null
      };
      this.snObj = {};
      this.radioObj = {};
      this.templateList = [];
      this.autoGenFlag = false;
      this.loading1 = false;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      console.log(this.queryParams, "=====queryParams===");
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      // this.reset();
      console.log(row, "row");
      this.indexCodeDisabled = false;
      this.failedSncode = [];
      this.snObj = {};
      this.open = true;
      this.QcFqcAcInspectionHead = row;
      this.form = { ...row };
      this.form.inspectionDate = new Date();
      this.title =
        row.productType == "WR"
          ? "OQC整车控制器检验单"
          : row.productType == "AC"
            ? "OQC直流充电桩检验单"
            : "OQC出库检验单";
      this.optType = "add";
      let id =
        row.productType == "DC"
          ? "10"
          : row.productType == "AC"
            ? "20"
            : row.productType == "VM"
              ? "21"
              : "10";
      this.templatePost(row.oqcId, row.oqcTempleteId);
      //模板id
      this.templateId = row.oqcTempleteId;
      this.getabnormalData();
    },
    /** 提交按钮 */
    submitForm() {
      console.log(this.templateList, "=====templateList===");
      console.log(this.snObj, this.QcFqcAcInspectionHead, "=====snObj===");
      let QcFqcAcInspectionDto = [];
      let bool = false;
      let snBool = false;
      for (let i = 0; i < this.form.samplingQuantity; i++) {
        let obj = { ...this.form };
        obj.snCode = this.snObj[`snCode${i}`];
        if (!obj.snCode) {
          snBool = true;
        }
        for (let j = 0; j < this.failedSncode.length; j++) {
          if (this.snObj[`snCode${i}`] === this.failedSncode[j].snCode) {
            obj.qcInspectionResult = {
              snCode: this.failedSncode[j].snCode,
              productType: this.form.productType,
              exceptionLogList: this.failedSncode[j].errorList,
              inspectionType: "2",
              checkResult: this.form.checkResult,
              repairState: this.failedSncode[j].repairState
            };
          }
        }
        obj.qcFqcAcInspectionHead = this.QcFqcAcInspectionHead;
        obj.qcOqcInspectionItemList = [];
        this.templateList.map((item, index) => {
          let type = item.attrObj.type;
          let attr2 = {};
          if (type == "2") {
            attr2.num = item.attrObj[`num${i}`];
          } else if (type == "4") {
            attr2 = {
              lStandard: item.attrObj.lStandard,
              wStandard: item.attrObj.wStandard,
              hStandard: item.attrObj.hStandard,
              lNum: item.attrObj[`lNum${i}`],
              wNum: item.attrObj[`wNum${i}`],
              hNum: item.attrObj[`hNum${i}`]
            };
          }
          obj.qcOqcInspectionItemList.push(
            Object.assign({}, item, {
              checkResult: item[`checkResult${i}`],
              snCode: this.snObj[`snCode${i}`],
              attr2: JSON.stringify(attr2)
            })
          );
        });
        QcFqcAcInspectionDto.push(obj);
      }
      console.log(QcFqcAcInspectionDto, "======QcFqcAcInspectionDto=========");
      for (let i = 0; i < QcFqcAcInspectionDto.length; i++) {
        for (
          let j = 0;
          j < QcFqcAcInspectionDto[i].qcOqcInspectionItemList.length;
          j++
        ) {
          const element =
            QcFqcAcInspectionDto[i].qcOqcInspectionItemList[j].checkResult;
          console.log(element);
          if (element === undefined) {
            bool = true;
          }
        }
      }
      if (bool) {
        this.$message({
          message: "请填写检验结果！！！",
          type: "warning"
        });
        return;
      }

      if (snBool) {
        this.$message({
          message: "请填写SN码（序列号）！！！",
          type: "warning"
        });
        return;
      }
      this.$refs["form"].validate((valid, value) => {
        console.log(valid, value, "===valid===");
        let params = {};
        params.QcFqcAcInspectionDto = QcFqcAcInspectionDto;
        console.log(QcFqcAcInspectionDto, "提交的QcFqcAcInspectionDto");
        if (valid) {
          addInspection(QcFqcAcInspectionDto).then(response => {
            this.$modal.msgSuccess("新增成功");
            this.open = false;
            this.reset();
            this.getList();
          });
        } else {
        }
      });
    },
    // 获取新增表格列表
    templatePost(id, templateId) {
      this.loading1 = true;
      let params = {
        oqcTempleteId: templateId,
        oqcId: id
      };
      templateindexList(params).then(response => {
        let list = [];
        response.data.map((item, index) => {
          list.push(
            Object.assign({}, item, {
              attrObj: item.attr1 ? JSON.parse(item.attr1) : { type: "0" }
            })
          );
        });
        this.templateList = list;
        console.log(this.templateList, "=========list===========");
        this.getSpanArr(response.data);
        this.loading1 = false;
      });
    },
    // 行合并
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0 || columnIndex == 1) {
        const _row = this.spanArr[rowIndex]; // 合并行数
        const _col = this.spanArr[rowIndex] > 0 ? 1 : 0; // 合并的列数
        return {
          rowspan: _row,
          colspan: _col
        };
      }
    },
    // 按照类型合并
    getSpanArr(data) {
      this.spanArr = []; // tip: 后台获取完成数据后，一定要重置spanArr=[],避免出现合并混乱！！！！！
      if (data.length > 0) {
        for (let i = 0; i < data.length; i++) {
          // 当为第一行时
          if (i === 0) {
            this.spanArr.push(1);
            this.pos = 0;
          } else {
            // 判断当前值是否与上一行的【名称】相等，相等则进行合并
            if (data[i].indexType === data[i - 1].indexType) {
              this.spanArr[this.pos] += 1; // 合并单元格：合并的行数 +1
              this.spanArr.push(0); // 0代表单元格是不需要显示, 已经被合并的单元格
            } else {
              this.spanArr.push(1); // 1代表当前这行的数据需要被显示
              this.pos = i;
            }
          }
        }
      }
    },
    //全选按钮事件
    checkAllChange(value, i) {
      console.log(value, i, "=====iii=======");
      let objName = "checkResult" + i;
      let list = [];
      this.templateList.map((item, index) => {
        list.push(Object.assign({}, item, { [objName]: 1 }));
      });
      console.log(list);
      this.templateList = list;
    },
    // 判断是否显示打钩单选
    judegShow(attr) {
      return true;
    },
    // 判断当前是否是合格
    checkChange(value) {
      let failedIndex = 0;
      let failedSncode = [];
      let qualifiedQuantity = 0;
      for (let i = 0; i < this.form.samplingQuantity; i++) {
        let str = "checkResult" + i;
        let bool = this.templateList.every(item => item[str] != 0);
        if (!bool) {
          failedIndex++;
          failedSncode.push({
            snCode: this.snObj[`snCode${i}`],
            errorList: [{}]
          });
        } else {
          qualifiedQuantity++;
        }
        console.log(bool, failedSncode, "=====failedSncode=====bool====");
      }
      this.form.unqualifiedQuantity = failedIndex;
      this.form.qualifiedQuantity = qualifiedQuantity;
      this.failedSncode = failedSncode;
      console.log(this.templateList, "====== this.templateList=====");
      // let bool = this.templateList.every(({ checkResult }) => checkResult == 1);
      this.form.checkResult = failedIndex === 0 ? 1 : 0;
    },
    // 异常记录增加
    errorAdd(item, i) {
      let obj = {};
      this.failedSncode[i].errorList.push(obj);
    },
    // 删除异常记录
    errorDel(index, i) {
      this.failedSncode[i].errorList.splice(index, 1);
    },
    //图片上传成功
    handleImgUplaoded(imgUrl, i, index) {
      console.log(imgUrl, i, "=========");
      this.failedSncode[i].errorList[index].fileName = imgUrl;
      // this.form.sopUrl = imgUrl;
    },
    //图片移除
    handleImgRemoved(imgUrl) {
      console.log(imgUrl);
      this.form.sopUrl = null;
    },
    inputStandard(e, row, index, i) {
      console.log(row, "=====row=====");
      let judType = row.attrObj.judType;
      let num = row.attrObj[`num${i}`];
      let standard = row.attrObj.standard;
      let min = row.attrObj.min;
      let max = row.attrObj.max;
      if (judType == "0") {
        // =
        if (num == standard) {
          this.templateList[index][`checkResult${i}`] = 1;
        } else {
          this.templateList[index][`checkResult${i}`] = 0;
        }
      } else if (judType == "1") {
        // >=
        if (Number(num) >= Number(standard)) {
          console.log(num, "==1=");
          this.templateList[index][`checkResult${i}`] = 1;
        } else {
          console.log(num, "=0==");
          this.templateList[index][`checkResult${i}`] = 0;
        }
      } else if (judType == "2") {
        // <=
        if (Number(num) <= Number(standard)) {
          this.templateList[index][`checkResult${i}`] = 1;
        } else {
          this.templateList[index][`checkResult${i}`] = 0;
        }
      } else if (judType == "3") {
        if (Number(num) >= Number(min) && Number(num) <= Number(max)) {
          console.log(true, "=====");
          this.templateList[index][`checkResult${i}`] = 1;
        } else {
          this.templateList[index][`checkResult${i}`] = 0;
        }
      }
      let obj1 = { ...this.templateList[index] };
      this.$set(this.templateList, index, obj1);
    },
    inputCheckout(e, row, index, i) {
      let lStandard = row.attrObj.lStandard;
      let wStandard = row.attrObj.wStandard;
      let hStandard = row.attrObj.hStandard;
      let lnum = row.attrObj[`lNum${i}`];
      let wnum = row.attrObj[`wNum${i}`];
      let hnum = row.attrObj[`hNum${i}`];
      if (lnum == lStandard && wnum == wStandard && hnum == hStandard) {
        console.log(true, "=====");
        this.templateList[index][`checkResult${i}`] = 1;
      } else {
        this.templateList[index][`checkResult${i}`] = 0;
      }

      let obj1 = { ...this.templateList[index] };
      this.$set(this.templateList, index, obj1);
    },
    getabnormalData() {
      let params = {
        templateId: this.templateId,
        productType: this.form.productType
      };
      console.log(params, "params");
      getabnormalList(params).then(res => {
        console.log(res, "异常list");
        this.abnormalList = res.data;
        console.log(this.abnormalList, "this.abnormalList");
      });
    },
    // 详情页面
    viewReport(isEdit, row) {
      this.detailVisible = true;
      this.$nextTick(() => {
        this.$refs.detailOrUpdate.init(isEdit, row);
      });
    },
    //输入sn码校验是否正确
    snbutton(e) {
      console.log(e, "eeee");
      var myInputOrder = document.getElementById("sncode-input");
      myInputOrder.onkeydown = even => {
        if (even.key == "Enter") {
          let params = {
            snCode: e,
            productCode: this.form.productCode
          };
          OqccheckSncode(params).then(res => {
            if (res.code == 200) {
              console.log(res, "校验sn码的res");
              this.$modal.msgSuccess(res.msg);
            }
          });
        }
      };
    },
    // 自动计算合格不合格数量
    autoInput(e, type, name) {
      if (e > this.form.quinspection) {
        this.$message({
          message: "数量不允许超过报检数量！！！",
          type: "warning"
        });
        this.form[type] = 0;
      } else {
        this.form[name] = this.form.quinspection - this.form[type];
      }
    }
  }
};
</script>
<style scoped>
.tableItem .el-form-item__content {
  margin-left: 0px !important;
}

.tableItem ::v-deep .el-form-item__content {
  margin-left: 0px !important;
}

.headerDiv {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialogContent ::v-deep .el-upload--picture-card {
  width: 80px;
  height: 80px;
  line-height: 80px;
}

.dialogContent .el-table {
  font-size: 12px;
}

ul li {
  list-style: none;
}

.mInput {
  display: flex;
  align-items: center;
  margin-bottom: 5px;
}

.el-icon-circle-plus-outline {
  font-size: 16px;
}

.el-icon-remove-outline {
  font-size: 16px;
}
</style>
